package com.adkun.community.config;

import com.UpYun;
import com.adkun.community.config.properties.UpYunProperties;
import com.upyun.RestManager;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * UpYun配置
 * @author adkun
 */
@Configuration
@EnableConfigurationProperties({UpYunProperties.class})
public class UpYunConfig {

    @Bean
    public List<RestManager> upYun(UpYunProperties properties) {
        RestManager upYun1 = new RestManager(properties.getBucketName().getHeader(), properties.getUsername(), properties.getPassword());
        RestManager upYun2 = new RestManager(properties.getBucketName().getShare(), properties.getUsername(), properties.getPassword());

        // 详细配置
        upYun1.setTimeout(properties.getOutTime());
        upYun1.setApiDomain(RestManager.ED_AUTO);
        upYun2.setTimeout(properties.getOutTime());
        upYun2.setApiDomain(RestManager.ED_AUTO);

        List<RestManager> list = new ArrayList<>(2);
        list.add(upYun1);
        list.add(upYun2);
        return list;
    }
}
